home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / option.exe / TOPTION.CPP < prev    next >
C/C++ Source or Header  |  1992-10-25  |  4KB  |  171 lines

  1. /*------------------------------------------------------------*/
  2. /* filename -       thistory.cpp                              */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TOption member functions                  */
  6. /*------------------------------------------------------------*/
  7.  
  8. /*------------------------------------------------------------*/
  9. /*                                                            */
  10. /*    Turbo Vision -  Version 1.0                             */
  11. /*                                                            */
  12. /*                                                            */
  13. /*    Copyright (c) 1991 by Borland International             */
  14. /*    All Rights Reserved.                                    */
  15. /*                                                            */
  16. /*------------------------------------------------------------*/
  17.  
  18. #define Uses_TOption
  19. #define Uses_TKeys
  20. #define Uses_TRect
  21. #define Uses_TEvent
  22. #define Uses_TInputLine
  23. #define Uses_TOptionWindow
  24. #define Uses_TWindow
  25. #define Uses_TCollection
  26. #define Uses_opstream
  27. #define Uses_ipstream
  28. #define Uses_TStreamableClass
  29. #include <tv.h>
  30. #include "TOption.h"
  31.  
  32. #if !defined( __CTYPE_H )
  33. #include <ctype.h>
  34. #endif  // __CTYPE_H
  35.  
  36. #if !defined( __STRING_H )
  37. #include <String.h>
  38. #endif  // __STRING_H
  39.  
  40. #if !defined( __DOS_H )
  41. #include <Dos.h>
  42. #endif  // __DOS_H
  43.  
  44. #define cpOption "\x16\x17"
  45.  
  46. const char * const near TOption::name = "TOption";
  47. __link( RView )
  48. __link( RInputLine )
  49.  
  50. TStreamableClass ROption( TOption::name,
  51.                           TOption::build,
  52.                           __DELTA(TOption)
  53.                          );
  54. const char * near TOption::icon = "\xDE~\x19~\xDD";
  55.  
  56.  
  57. TOption::TOption( const TRect& bounds,
  58.                     TInputLine *aLink,
  59.                     TCollection *aList ) :
  60.         TView(bounds),
  61.         link( aLink ),
  62.         items( aList )
  63.     {
  64.     options |= ofPostProcess;
  65.     eventMask |= evBroadcast;
  66.     }
  67.  
  68. void TOption::shutDown()
  69.     {
  70.     link = 0;
  71.     items = 0;
  72.     TView::shutDown();
  73.     }
  74.  
  75. void TOption::draw()
  76.     {
  77.     TDrawBuffer b;
  78.  
  79.     b.moveCStr( 0, icon, getColor(0x0102) );
  80.     writeLine( 0, 0, size.x, size.y, b );
  81.     }
  82.  
  83. TPalette& TOption::getPalette() const
  84.     {
  85.     static TPalette palette( cpOption, sizeof( cpOption )-1 );
  86.     return palette;
  87.     }
  88.  
  89. void TOption::handleEvent( TEvent& event )
  90.     {
  91.     TOptionWindow *optionWindow;
  92.     TRect  r, p;
  93.     ushort c;
  94.  
  95.     TView::handleEvent( event );
  96.     if( event.what == evMouseDown ||
  97.           ( event.what == evKeyDown &&
  98.             ctrlToArrow( event.keyDown.keyCode ) ==  kbDown &&
  99.             (link->state & sfFocused) != 0
  100.           )
  101.       )
  102.         {
  103.         link->select();
  104.         r = link->getBounds();
  105.         r.a.x--;
  106.         r.b.x++;
  107.         r.b.y += 7;
  108.         r.a.y--;
  109.         p = owner->getExtent();
  110.         r.intersect( p );
  111.         r.b.y--;
  112.         optionWindow = initOptionWindow( r );
  113.         if( optionWindow != 0 )
  114.             {
  115.             c = owner->execView( optionWindow );
  116.             if( c == cmOK )
  117.                 {
  118.                 char rslt[256];
  119.                 optionWindow->getSelection( rslt );
  120.                 strncpy( link->data, rslt, link->maxLen );
  121.                 link->selectAll( True );
  122.                 link->drawView();
  123.                 }
  124.             destroy( optionWindow );
  125.             }
  126.         clearEvent( event );
  127.         }
  128.     }
  129.  
  130. TCollection *TOption::list()
  131.     {
  132.     return items;
  133.     }
  134.  
  135. void TOption::newList( TCollection *aList )
  136.     {
  137.     destroy( items );
  138.     items = aList;
  139.     }
  140.  
  141. TOptionWindow *TOption::initOptionWindow( const TRect& bounds )
  142.     {
  143.     TOptionWindow *p = new TOptionWindow( bounds, items );
  144.     p->helpCtx = link->helpCtx;
  145.     return p;
  146.     }
  147.  
  148. void TOption::write( opstream& os )
  149.     {
  150.     TView::write( os );
  151.     os << link << items;
  152.     }
  153.  
  154. void *TOption::read( ipstream& is )
  155.     {
  156.     TView::read( is );
  157.     is >> link >> items;
  158.     return this;
  159.     }
  160.  
  161. TStreamable *TOption::build()
  162.     {
  163.     return new TOption( streamableInit );
  164.     }
  165.  
  166. TOption::TOption( StreamableInit ) : TView( streamableInit )
  167.     {
  168.     }
  169.  
  170.  
  171.